//
//  MainVC.m
//  OC_Poj_demo
//
//  Created by weixin on 2018/7/18.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainVC.h"
#import "MeVC.h"

/* MARK: ================= 新首页 =================*/
#import "MainTitleV.h"
#import "MainScrollV.h"
#import "Main_Title_View_WX.h"

/* MARK: ================= 后面不需要可以 =================*/
#import "Ugc_Detail_VC_WX.h"
#import <SystemConfiguration/CaptiveNetwork.h>//网络框架
#import "Ugc_Receive_VC_WX.h"
#import "Ugc_ReleaseFailure_VC.h"
#import "failToSendView.h"
#import "UgcReleaseFailureModel.h"



#define viewblackH 3
#define viewblackY 40-viewblackH
#define bottomH (Is_Iphone_X_Series ? 80 : 45)


@interface MainVC ()

@property (nonatomic,strong)NSMutableArray * arrM;

@property (nonatomic,strong)UIImageView * imageUser;

/* FIXME: ================= 新首页 UI 修改 ================= */

//@property (nonatomic,strong)MainTitleV * TitleV;

@property (nonatomic,strong)MainScrollV * ScrollV;

@property (nonatomic,strong)Main_Title_View_WX * TitleV;


/* FIXME: ================= text ================= */

@end

@implementation MainVC

- (void)viewDidLoad {

    [super viewDidLoad];
    
    [self setNav];

    [self loaddata];
    
    if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]) {
        self.view.backgroundColor = Main_Token_Model_MANAGER.backgroundColor ;
    }

}

-(void)loaddata{
    [self setUI];
//    [self.baseNavigationView.rightButton1 setTitle:@"" forState:(UIControlStateNormal)];

    

}


-(void)setUI{
    
//    self.view.backgroundColor = HexColor(0xf5f5f5);
//    BaseView *bgView = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
//    bgView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:bgView];
//    [self.view addSubview:self.ScrollV];
//    [self.view addSubview:self.TitleV];
//    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.equalTo(self.view).offset(0);
//        make.bottom.equalTo(self.TitleV.mas_bottom).offset(0);
//    }];
    
    self.view.backgroundColor = HexColor(0xf5f5f5);
    
    BaseView *bgView = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
        bgView.backgroundColor = Main_Token_Model_MANAGER.backgroundColor ;
    }else{
        bgView.backgroundColor = [UIColor whiteColor];

    }

    [self.view addSubview:bgView];
    

    [self.view addSubview:self.ScrollV];
    [self.view addSubview:self.TitleV];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.TitleV.mas_bottom).offset(0);
    }];
    
    
    [self.ScrollV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.TitleV.mas_bottom).offset(0);
        make.left.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(-TabbarHeight);
    }];
    
    
//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,kStatusBarHeight, SCREEN_WIDTH, kScreenH-kStatusBarHeight-60)];
//    [view addSubview:self.ScrollV];
//    [view addSubview:self.TitleV];

//    [self.view addSubview: view];


}





-(void)setNav{
    [self.baseNavigationView setHiddenNav:YES VC:self];
}


-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    if (kUSER_isPublishImage.type == YES && !kUSER_isPublishImage.typeClose) {
        kUSER_isPublishImage.hidden = YES;
    }
    
}





- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if (kUSER_isPublishImage.type == YES && !kUSER_isPublishImage.typeClose) {
        kUSER_isPublishImage.hidden = NO;
    }
    self.baseNavigationView.rightButton1.hidden = YES;
    
//    if (kUSER_INFO_MANAGER.userIsLogin) {
//        NSString *userImage = [NSString stringWithFormat:@"%@%@",RootUrlImage,kUSER_INFO_MANAGER.avatar];
//
//        [self.baseNavigationView.rightButton1 sd_setImageWithURL:[NSURL URLWithString:userImage]forState:UIControlStateNormal];
//    }else{
//        [self.baseNavigationView.rightButton1 setTitle:@"登录" forState:(UIControlStateNormal)];
//        [self.baseNavigationView.rightButton1 sd_setImageWithURL:[NSURL URLWithString:@""] forState:UIControlStateNormal];
//    }
    self.tabBarController.tabBar.hidden=NO;
    
    /** 处理发布页面tabbar显示问题 */
//    if ([DEFAULReleaseV iseqHidden]) {
//        [self.tabBarController.tabBar setHidden:NO];
//    }else{
//        [self.tabBarController.tabBar setHidden:YES];
//    }

    if (!self.isfirst) {
        self.isfirst = YES;
    }
    
}


//更新首页样式
-(void)chageView{
    
//    self.ScrollV.tbv3.frame = CGRectMake(kScreenW, 0, kScreenW, kScreenH-kStatusBarHeight-100-50-kBottomSafeHeight+70);
}


-(Main_Title_View_WX *)TitleV{
    if (!_TitleV) {
        _TitleV = [[Main_Title_View_WX alloc]initWithFrame:CGRectMake(0,kStatusBarHeight, SCREEN_WIDTH, 40 )];
        _TitleV.backgroundColor = [UIColor whiteColor];
        [_TitleV setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];
        //        NSMutableArray *arrMNormal = [[NSMutableArray alloc]initWithArray:@[@"关注",@"精选",@"动态"]];
        //        _TitleV.arrMNormal = arrMNormal;
        _TitleV.state = MainTitleVStateLogo;
        
        @weakify(self);
        [_TitleV setBlcokIndex:^(NSInteger index) {
            @strongify(self);
            self.ScrollV.contentOffset = CGPointMake((index)*kScreenW, 0);
        }];
    }
    return _TitleV;
}
-(MainScrollV *)ScrollV{
    if (!_ScrollV) {
        _ScrollV = [[MainScrollV alloc]initWithFrame:CGRectMake(0,0, kScreenW, kScreenH-kStatusBarHeight-bottomH)];
//        _ScrollV.backgroundColor = [UIColor redColor];
//        _ScrollV.arrTitle = self.TitleV.arrMSelect;
        _ScrollV.arrTitle = @[@""];

        @weakify(self);
        [_ScrollV setBlock:^(NSInteger index) {
            @strongify(self);
            [self.TitleV changeBtn:index+100];
        }];
    }
    return _ScrollV;
}

@end
